﻿using Newtonsoft.Json;
using PinusTools.DataConverter;
using PinusTools.Enums;

namespace GameSdk.MsgHelper
{
    /// <summary>
    /// 基础消息包
    /// </summary>
    public class BasicMsgHelper
    {
        /// <summary>
        /// 连接服务器请求包
        /// </summary>
        public static byte[] GetConnectMsg()
        {
            var handshakeBuffer = new
            {
                sys = new
                {
                    type = "js-websocket",
                    version = "0.0.1"
                }
            };

            var strJson = JsonConvert.SerializeObject(handshakeBuffer, Formatting.None);
            var protocolData = Protocol.StrEncode(strJson);
            var sendData = Package.Encode(PackageEnum.TYPE_HANDSHAKE, protocolData);

            return sendData;
        }

        /// <summary>
        /// 连接服务器响应包
        /// </summary>
        public static byte[] GetConnectAckMsg()
        {
            var sendData = Package.Encode(PackageEnum.TYPE_HANDSHAKE_ACK);
            return sendData;
        }

        /// <summary>
        /// 心跳检验包
        /// </summary> 
        public static byte[] GetHeartBeatMsg()
        {
            var sendData = Package.Encode(PackageEnum.TYPE_HEARTBEAT);
            return sendData;
        }
    }
}